package com.fy.config;

import com.fy.filter.JWTVerifyFilter;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;

import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

/**
 * 江迪
 */

//声明该类为配置类
//@Configuration
//作用：
// 1、加载了WebSecurityConfiguration配置类, 配置安全认证策略。
// 2、加载了AuthenticationConfiguration, 配置了认证信息.
//@EnableWebSecurity(debug = true)
//开启权限认证
//@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {



    @Override
    public void configure(WebSecurity web) throws Exception {
        super.configure(web);
    }




    //重写http的configure方法
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().antMatchers("/user/login","/user/checkToken","/verify","/swagger-ui.html","/swagger-resources/**","/webjars/**","/v2/**","/api/**")
                .permitAll().anyRequest().authenticated();


        http.csrf().disable();


        //跨域放行
        http.cors();


        //将JWTVerifyFilter放入过滤连中
        http.addFilter(new JWTVerifyFilter(authenticationManager()));
    }
}
